
<style scoped>
    .layout{
        background: #f5f7f9;
        position: relative;
        overflow: hidden;
    }
    .layout-breadcrumb{
        padding: 10px 15px 0;
    }
    .layout-content{
        min-height: 200px;
        margin: 15px;
        overflow: hidden;
        background: #fff;
        border-radius: 4px;
    }
    .layout-content-main{
        padding: 10px;
    }
    .layout-copy{
        text-align: center;
        padding: 10px 0 20px;
        color: #9ea7b4;
    }
    .layout-menu-left{
        background: #464c5b;
        min-height: 100vh;
/*        position:fixed;
        top:0;
        left:0;*/
    }
    .layout-header{
        height: 60px;
        background: #fff;
        box-shadow: 0 1px 1px rgba(0,0,0,.1);
    }
    .layout-logo-left{
        width: 90%;
        height: 30px;
        background: #5b6270;
        border-radius: 3px;
        margin: 15px auto;
    }
    .layout-logo-left > h1{
        color:#fff;
        text-align: center;
        line-height:30px;
        font-size:16px;
    }
    .layout-ceiling-main a{
        color: #9ba7b5;
    }
    .layout-hide-text .layout-text{
        display: none;
    }
    .ivu-col{
        transition: width .2s ease-in-out;
    }
</style>
<template>
    <div class="layout" :class="{'layout-hide-text': spanLeft < 5}">
        <Row type="flex">
            <Col :span="spanLeft" class="layout-menu-left">
                <Menu :active-name='path' theme="dark" width="auto" @on-select="routeTo">
                    <div class="layout-logo-left">
                        <h1>导航中心</h1>
                    </div>
                    <MenuItem v-for='(item, key) in navList' :name='item.href' :key='item.id' >
                        <Icon :type='item.iconType' :size="iconSize"></Icon>
                        <span class="layout-text">{{item.name}}</span>
                    </MenuItem>
                </Menu>
            </Col>
            <Col :span="spanRight">
                <div class="layout-header">
                    <Button type="text" @click="toggleClick">
                        <Icon type="navicon" size="32"></Icon>
                    </Button>
                </div>
                <div class="layout-breadcrumb">
                    <Breadcrumb>
                        <BreadcrumbItem>{{this.$route.path}}</BreadcrumbItem>
                    </Breadcrumb>
                </div>
                <div class="layout-content">
                    <div class="layout-content-main">
                        <router-view></router-view>
                    </div>
                </div>
                <div class="layout-copy">
                    2011-2016 &copy; TalkingData
                </div>
            </Col>
        </Row>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                spanLeft: 5,
                spanRight: 19,
                path:this.$route.path,
                navList:[{
                    name:'首页',
                    href:'/admin/home',
                    iconType:'home'
                },{
                    name:'增加',
                    href:'/admin/add',
                    iconType:'plus'                    
                },{
                    name:'草稿箱',
                    href:'/admin/drafts',
                    iconType:'trash-a'                    
                },{
                    name:'统计',
                    href:'/admin/statistics',
                    iconType:'pie-graph' 
                },{
                    name:'个人信息',
                    href:'/admin/about',
                    iconType:'person'
                }]
            }
        },
        computed: {
            iconSize () {
                return this.spanLeft === 5 ? 18 : 24;
            }
        },
        mounted(){
            const that = this;
            this.$http.get( 
                that.surl+'checkLogin?sessionID='+that.$cookie.get('sessionID')
            )
            .then(function (response) {
                if(!response.data){
                    that.$router.push('/admin/login');
                }
              })
            .catch(function (error) {
                that.$router.push('/admin/404');
            });
        },
        watch:{

        },
        methods: {
            toggleClick () {
                if (this.spanLeft === 5) {
                    this.spanLeft = 2;
                    this.spanRight = 22;
                } else {
                    this.spanLeft = 5;
                    this.spanRight = 19;
                }
            },
            routeTo(path){
                this.$router.push(path);
            }
        }
    }
</script>